package com.xqboss.apps.controller.equipment;

import com.xqboss.apps.constant.Config;
import com.xqboss.apps.dto.IdDto;
import com.xqboss.apps.dto.equipment.*;
import com.xqboss.apps.service.equipment.EquipmentSmeltService;
import com.xqboss.apps.vo.equipment.*;
import com.xqboss.common.annotation.RepeatSubmit;
import com.xqboss.common.core.controller.BaseController;
import com.xqboss.common.core.domain.PageList;
import com.xqboss.common.core.domain.R;
import com.xqboss.system.service.ISysConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Trent
 * @date 2023/8/16
 */
@Api(tags = "装备-装备熔炼")
@RequestMapping("/apps/equipment/smelt")
@RestController
public class EquipmentSmeltController extends BaseController {

    @Autowired
    private EquipmentSmeltService smeltService;

    @Autowired
    private ISysConfigService sysConfigService;


    @ApiOperation("首页")
    @GetMapping("/index")
    public R<AppEquipmentSmeltIndexVo> index() {
        return R.ok(smeltService.appIndex(getUserId()));
    }


    @ApiOperation("获取熔炼时长和加速消耗")
    @PostMapping("/get-waiting-time")
    public R<AppEquipmentSmeltWaitingVo> getWaitingTime(@RequestBody @Validated EquipmentSmeltSaveDto params) {
        params.setUserId(getUserId());
        return R.ok(smeltService.getWaitingTime(params));
    }


    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("熔炼")
    @PostMapping("/save")
    public R<List<AppEquipmentSmeltEquipmentProduceVo>> save(@RequestBody @Validated EquipmentSmeltSaveDto params) {
        params.setUserId(getUserId());
        return R.ok(smeltService.add(params));
    }


    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("加速熔炼")
    @PostMapping("/speed-up")
    public R<Long> speedUp(@RequestBody @Validated EquipmentSmeltSpeedUpDto params) {
        params.setUserId(getUserId());
        return R.ok(smeltService.speedUp(params));
    }


    @RepeatSubmit(interval = 1000, justUrl = true)
    @ApiOperation("领取熔炼产出")
    @PostMapping("/receive")
    public R<List<AppEquipmentSmeltEquipmentProduceVo>> receive(@RequestBody @Validated IdDto params) {
        return R.ok(smeltService.receive(params.getId()));
    }


    @ApiOperation("记录分页列表")
    @GetMapping("/record/page/list")
    public R<List<AppEquipmentSmeltDetailVo>> recordPageList(EquipmentSmeltRecordQueryDto params) {
        params.setUserId(getUserId());
        PageList<AppEquipmentSmeltDetailVo> pageList = smeltService.pageList(params);
        return R.ok(pageList.getList(), pageList.getTotal());
    }


    @ApiOperation("记录消耗列表")
    @GetMapping("/record/consume/list")
    public R<List<AppEquipmentSmeltConsumeDetailVo>> recordConsumeList(EquipmentSmeltRecordConsumeQueryDto params) {
        params.setUserId(getUserId());
        List<AppEquipmentSmeltConsumeDetailVo> list = smeltService.consumeDetailList(params);
        return R.ok(list);
    }


    @ApiOperation("说明")
    @GetMapping("/explain-info")
    public R<String> explainInfo() {
        return R.ok(sysConfigService.getValue(Config.Sys.Other.装备熔炼说明));
    }
}
